昨天我們能讓 contract 接收 ether 了,那如果想在 contract 裡把 ether 送給別人應該要怎麼做呢?
就讓我們來討論一下 Address type 與他的一些操作吧!
本日合約:
pragma solidity ^0.4.25;
contract Address {
function() public payable {}
function Balance() public view returns (uint256) {
return address(this).balance;
}
function Transfer(uint256 amount) public returns (bool) {
msg.sender.transfer(amount * 1 ether);
return true;
}
function SendWithoutCheck(uint256 amount) public returns (bool) {
msg.sender.send(amount * 1 ether);
return true;
}
function SendWithCheck(uint256 amount) public returns (bool) {
require(msg.sender.send(amount * 1 ether), "Send failed");
return true;
}
}
本日影片:
https://youtu.be/s82EGggALMg
Smart Contract 實戰教學播放清單:
https://www.youtube.com/playlist?list=PLHmOMPRfmOxSJcrlwyandWYiuP9ZAMYoF